package com.itboy.search.web;

import com.itboy.search.service.MallSearchService;
import com.itboy.search.vo.SearchParam;
import com.itboy.search.vo.SearchResult;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Validated
@Api(value = "检索页面", tags = {"检索页面"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Controller
@RequestMapping("/search")
public class SearchWebController {

	private final MallSearchService mallSearchService;

	/**
	 * 跳转检索页面=》检索
	 * @param param
	 * @param model
	 * @return
	 */
	@GetMapping("/list.html")
	public String listPage(SearchParam param, Model model){
		//1. 根据页面传递过来的查询参数，到ES中检索商品
		SearchResult searchResult=mallSearchService.search(param);
		model.addAttribute("result",searchResult);
		return "list";
	}
}
